package com.nmsl.registration.controller;

import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.core.page.TableDataInfo;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.registration.domain.skxVisitRecord;
import com.nmsl.registration.service.skxIVisitRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 就诊记录Controller
 * 
 * @author sn
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/skx/record")
public class skxVisitRecordController extends BaseController
{
    @Autowired
    private skxIVisitRecordService visitRecordService;

    /**
     * 查询就诊记录列表
     */
    @PreAuthorize("@ss.hasPermi('sn:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(skxVisitRecord visitRecord)
    {
        startPage();
        List<skxVisitRecord> list = visitRecordService.selectVisitRecordList(visitRecord);
        return getDataTable(list);
    }

    /**
     * 导出就诊记录列表
     */
    @PreAuthorize("@ss.hasPermi('sn:record:export')")
    @Log(title = "就诊记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, skxVisitRecord visitRecord)
    {
        List<skxVisitRecord> list = visitRecordService.selectVisitRecordList(visitRecord);
        ExcelUtil<skxVisitRecord> util = new ExcelUtil<skxVisitRecord>(skxVisitRecord.class);
        util.exportExcel(response, list, "就诊记录数据");
    }

    /**
     * 获取就诊记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('sn:record:query')")
    @GetMapping(value = "/{visitRecordId}")
    public AjaxResult getInfo(@PathVariable("visitRecordId") Long visitRecordId)
    {
        return success(visitRecordService.selectVisitRecordByVisitRecordId(visitRecordId));
    }

    /**
     * 新增就诊记录
     */
    @PreAuthorize("@ss.hasPermi('sn:record:add')")
    @Log(title = "就诊记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody skxVisitRecord visitRecord)
    {
        return toAjax(visitRecordService.insertVisitRecord(visitRecord));
    }

    /**
     * 修改就诊记录
     */
    @PreAuthorize("@ss.hasPermi('sn:record:edit')")
    @Log(title = "就诊记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody skxVisitRecord visitRecord)
    {
        return toAjax(visitRecordService.updateVisitRecord(visitRecord));
    }

    /**
     * 删除就诊记录
     */
    @PreAuthorize("@ss.hasPermi('sn:record:remove')")
    @Log(title = "就诊记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{visitRecordIds}")
    public AjaxResult remove(@PathVariable Long[] visitRecordIds)
    {
        return toAjax(visitRecordService.deleteVisitRecordByVisitRecordIds(visitRecordIds));
    }

    @PreAuthorize("@ss.hasPermi('sn:record:list')")
    @GetMapping("/infolist")
    public List<skxVisitRecord> list(@RequestParam Long patientId )
    {
        List<skxVisitRecord> list = visitRecordService.selectVisitRecordListBySkxId(patientId);
        return list;
    }
}
